﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Model.Entity;

namespace BLL
{
    public class ReturnBLL : BaseBLL
    {
        public Borrow canReturn(String rfid)
        {
            return dal.getBorrowDAL().canReturn(rfid);
        }

        public bool returnBook(Borrow borrow)
        {
            if (borrow != null)
            {
                borrow.isReturn = true;
                borrow.returnDate = DateTime.Now;
                dal.getBorrowDAL().update(borrow);
                return true;
            }
            else
            {
                return false;
            }
        }

        public UserAndBorrow getBorrowsByUser(int userId)
        {
            User user = dal.getUserDAL().get(userId);
            if (user == null)
            {
                return null;
            }
            else
            {
                return new UserAndBorrow(user, dal.getBorrowDAL().getByUserT(userId));
            }
        }
    }

    public class UserAndBorrow
    {
        public UserAndBorrow(User user, DataTable borrows)
        {
            this.user = user;
            this.borrows = borrows;
        }

        public User user { set; get; }

        public DataTable borrows { set; get; }        
    }
}
